﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace NMigrate
{
	public class ConsoleWriter : TextWriter
	{
		private ConsoleColor foregroundErrorColor;

		public ConsoleWriter(ConsoleColor foregroundErrorColor)
		{
			this.foregroundErrorColor = foregroundErrorColor;
		}
		public override Encoding Encoding
		{
			get
			{
				return Console.OutputEncoding;
			}
		}

		public override void WriteLine(string value)
		{
			Write(value + Environment.NewLine);
		}

		public override void Write(string value)
		{
			var oldColor = Console.ForegroundColor;
			try
			{
				Console.ForegroundColor = foregroundErrorColor;
				Console.Write(value);
			}
			finally
			{
				Console.ForegroundColor = oldColor;
			}
		}
	}
}
